//
//  ViewController.swift
//  PhotoBrowse
//
//  Created by huizhou.wang on 12/08/2023.
//  Copyright (c) 2023 huizhou.wang. All rights reserved.
//

import UIKit
import MSPhotoBrowse


class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("====================")
        
        
        
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let browser = MSPhotoBrowser(delegate: self)
        browser?.displayNavArrows = true
        browser?.displayActionButton = true
        browser?.alwaysShowControls = true
        browser?.enableSwipeToDismiss = true
        browser?.setCurrentPhotoIndex(0)
        browser?.snapshotView = UIApplication.shared.keyWindow?.rootViewController?.view.snapshotView(afterScreenUpdates: false)
        browser?.showMoreButton = false
        let nav = UINavigationController.init(rootViewController: browser!)
        self.present(nav, animated: true)
        print("----------------------------------")
    }

}

extension ViewController:MSPhotoBrowserDelegate {
    
    
    func numberOfPhotos(in photoBrowser: MSPhotoBrowser!) -> UInt {
        return 4
    }
    
    func photoBrowser(_ photoBrowser: MSPhotoBrowser!, photoAt index: UInt) -> MSPhotoProtocol! {
        if index < 3 {
            let imageName = "photo\(index)"
            return MSPhoto.init(image: UIImage(named:imageName ))
        } else {
            return MSPhoto.init(url: URL(string: "https://files.opayweb.com/images/merchant/saas/category/20230427849095690643099648.png"))
        }
        
    }
    
    
}

